{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "snmp \n",
    "简单网络管理协议，该协议能有支持网络管理系统，并且获取相关信息。\n",
    "\n",
    "\n",
    "## 安装snmp工具\n",
    "## ubuntu\n",
    "apt-get install snmpd snmp snmp-mibs-downloader\n",
    "\n",
    "## snmp配置文件\n",
    "vim /etc/snmp/snmpd.conf\n",
    "\n",
    "修改：\n",
    "agentAddress udp:0.0.0.0:161\n",
    "\n",
    "重启：\n",
    "/etc/init.d/snmpd restart\n",
    "\n",
    "测试：\n",
    "测试工具安装：\n",
    "Centos：yum install net-snmp-utils\n",
    "Ubuntu：apt-get install snmp\n",
    "\n",
    "# 获取客户端全部snmp信息\n",
    "snmpwalk -v 2c -c public 127.0.0.1\n",
    "\n",
    "# 获取oid对应的某一项值\n",
    "snmpwalk -v 2c -c public 127.0.0.1 iso.3.6.1.2.1.1.1.0\n",
    "\n",
    "\n",
    "## 安装 python 模块\n",
    "pip install pysnmp\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pysnmp.entity.rfc3413.oneliner import cmdgen\n",
    "\n",
    "cg = cmdgen.CommandGenerator()\n",
    "cg.getCmd(\n",
    "    ## snmpt 索引值\n",
    "    ## public 代表密钥方式\n",
    "    ## 0 代表2c版本\n",
    "    cmdgen.CommunityData('snmpt', 'public', 0),\n",
    "    ## 161 snmp的监听端口\n",
    "    cmdgen.UdpTransportTarget(('192.168.1.108', 161)),\n",
    "    ## oid 值，代表 获取系统基本信息\n",
    "    '1.3.6.1.2.1.1.1.0'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "snmp 系统oid参数：\n",
    "\n",
    "https://blog.csdn.net/qq_28657577/article/details/82834442"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
